﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bootstrap.MVC.Widgets
{
    public class WidgetBuilderBase<TModel, TBuilder, THtmlGenerator, TScriptGenerator> : 
                                    BuilderBase<TModel, TBuilder> , IWidgetBuilderBase<TBuilder>
        where TModel : IModelBase
        where TBuilder : class
        where THtmlGenerator : HtmlGeneratorBase<TModel>
        where TScriptGenerator : ScriptGeneratorBase<TModel>
    {
        protected TScriptGenerator ScriptGenerator;
        protected THtmlGenerator HtmlGenerator;
        

        public WidgetBuilderBase(TModel model, THtmlGenerator generator, TScriptGenerator scriptGenerator)
            : base(model)
        {
           
            this.Model = model;
            HtmlGenerator = generator;
            HtmlGenerator.Model = this.Model;
            ScriptGenerator = scriptGenerator;
        }

        public WidgetBuilderBase(TModel model) : base(model) { }
        
        public virtual void Render()
        {
            Model.ViewContext.Writer.Write(HtmlGenerator.Render());
            // Component.ViewContext.Writer.Write(ScriptGenerator.Render());
        }

        public TBuilder Text(string text)
        {
            Model.Text = text;
            return this as TBuilder;
        }

        public virtual TBuilder Disabled(bool disabled = true)
        {
            Model.Disabled = disabled;
            return this as TBuilder;
        }
    }

    public interface IWidgetBuilderBase<TBuilder>
    {
        TBuilder Disabled(bool disabled = true);
        TBuilder Text(string text);
    }
}
